<?php

    $items = array();
    $after_selected = false;
    $count = 0;
    foreach (Layout::o()->widget['menu']->getByTags(array('top_menu')) as $item) {
        $add_class_body = "sys_clear item";
        if (++$count==1) {
            $add_class_body .= strlen($add_class_body) ? ' ' : '';
            $add_class_body .= 'first-child';
        }
        if ($item->active) {
            $add_class_body .= strlen($add_class_body) ? ' ' : '';
            $add_class_body .= 'selected-link';
            $after_selected = true;
        } elseif ($after_selected) {
            $add_class_body .= strlen($add_class_body) ? ' ' : '';
            $add_class_body = 'after-selected-link';
            $after_selected = false;
        }
        $add_class = strlen($add_class_body) ? " class=\"{$add_class_body}\"" : "";
        $add_id = strlen($item->ident) ? 'menu-item-'.$item->ident : '';
        $add_id = strlen($add_id) ? ' id="'.$add_id.'"' : '';
        $str = '<span '.$add_id.$add_class.'>';
        if ($item->active) {
            if ($item->current) {
                $str .= '<span>'.$item->title.'</span>';
            } else {
                $str .= '<a href="'.$html->url($item->url_with_params).'">'.$item->title.'</a>';
            }
        } else {
            $str .= '<a href="'.$html->url($item->url_with_params).'">'.$item->title.'</a>';
        }
        $str .= '</span>';
        $items[] = $str;
    }

    ?><span id="top-menu"><?php
        $count = count($items);
        $i = 0;
        foreach ($items as $item) {
            ?><?=$item;?><?php
        }
    ?></span><?php

?>